package com.layui.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * @packageName: com.layui.controller
 * @name: UserController
 * @description:
 * @author: 董定卓
 * @dateTime: 2018/10/9 10:18
 */
@Controller
@RequestMapping("user")
public class UserController {

    @RequestMapping("getMenu")
    @ResponseBody
    public Object getMenu() {
        List<Map<String, Object>> menuList = new ArrayList<>();
        Map<String, Object> menuMap1 = new LinkedHashMap<>();
        menuMap1.put("title", "资源管理");
        menuMap1.put("icon", "layui-icon-rate");
        menuMap1.put("href", "/test1.html");
        menuMap1.put("spread", true);
        menuList.add(menuMap1);

        Map<String, Object> menuMap2 = new LinkedHashMap<>();
        menuMap2.put("title", "订单管理");
        menuMap2.put("icon", "layui-icon-cellphone");
        menuMap2.put("href", "/test2.html");
        menuMap2.put("spread", true);
        menuList.add(menuMap2);

        Map<String, Object> menuMap3 = new LinkedHashMap<>();
        menuMap3.put("title", "用户管理");
        menuMap3.put("icon", "layui-icon-username");
        menuMap3.put("href", "/test3.html");
        menuMap3.put("spread", true);

        List<Map<String, Object>> childList = new ArrayList<>();
        Map<String, Object> childMap1 = new LinkedHashMap<>();
        childMap1.put("title", "后台用户");
        childMap1.put("icon", "layui-icon-friends");
        childMap1.put("href", "/test4.html");
        childMap1.put("spread", false);
        childList.add(childMap1);

        Map<String, Object> childMap2 = new LinkedHashMap<>();
        childMap2.put("title", "会员管理");
        childMap2.put("icon", "layui-icon-face-smile-fine");
        childMap2.put("href", "/test5.html");
        childMap2.put("spread", false);
        childList.add(childMap2);

        menuMap3.put("children", childList);
        menuList.add(menuMap3);

        return menuList;
    }

    @RequestMapping("userList")
    @ResponseBody
    public Object userList(@RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "10") int limit) {
        List<Map<String, Object>> userList = new ArrayList<>();
        Map<String, Object> userMap1 = new HashMap<>();
        userMap1.put("id", 1001);
        userMap1.put("name", "user1");
        userMap1.put("sex", 2);
        userMap1.put("score", 99);
        userList.add(userMap1);

        Map<String, Object> userMap2 = new HashMap<>();
        userMap2.put("id", 1012);
        userMap2.put("name", "user12");
        userMap2.put("sex", 2);
        userMap2.put("score", 12);
        userList.add(userMap2);

        Map<String, Object> userMap3 = new HashMap<>();
        userMap3.put("id", 1008);
        userMap3.put("name", "user8");
        userMap3.put("sex", 1);
        userMap3.put("score", 33);
        userList.add(userMap3);

        Map<String, Object> userMap4 = new HashMap<>();
        userMap4.put("id", 1010);
        userMap4.put("name", "user1");
        userMap4.put("sex", 1);
        userMap4.put("score", 44);
        userList.add(userMap4);

        Map<String, Object> userMap5 = new HashMap<>();
        userMap5.put("id", 1009);
        userMap5.put("name", "user1");
        userMap5.put("sex", 2);
        userMap5.put("score", 55);
        userList.add(userMap5);

        Map<String, Object> userMap6 = new HashMap<>();
        userMap6.put("id", 1003);
        userMap6.put("name", "user1");
        userMap6.put("sex", 1);
        userMap6.put("score", 66);
        userList.add(userMap6);

        Map<String, Object> userMap7 = new HashMap<>();
        userMap7.put("id", 1002);
        userMap7.put("name", "user1");
        userMap7.put("sex", 1);
        userMap7.put("score", 77);
        userList.add(userMap7);

        Map<String, Object> userMap8 = new HashMap<>();
        userMap8.put("id", 1004);
        userMap8.put("name", "user1");
        userMap8.put("sex", 1);
        userMap8.put("score", 88);
        userList.add(userMap8);

        Map<String, Object> userMap9 = new HashMap<>();
        userMap9.put("id", 1009);
        userMap9.put("name", "user1");
        userMap9.put("sex", 1);
        userMap9.put("score", 99);
        userList.add(userMap9);

        Map<String, Object> userMap10 = new HashMap<>();
        userMap10.put("id", 1007);
        userMap10.put("name", "user1");
        userMap10.put("sex", 1);
        userMap10.put("score", 100);
        userList.add(userMap10);

        Map<String, Object> userMap11 = new HashMap<>();
        userMap11.put("id", 1005);
        userMap11.put("name", "user1");
        userMap11.put("sex", 2);
        userMap11.put("score", 11);
        userList.add(userMap11);

        Map<String, Object> userMap12 = new HashMap<>();
        userMap12.put("id", 1006);
        userMap12.put("name", "user1");
        userMap12.put("sex", 2);
        userMap12.put("score", 12);
        userList.add(userMap12);

        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
        result.put("msg", "success");
        int size = userList.size();
        result.put("count", size);
        int end = limit * page;
        result.put("data", userList.subList((page - 1) * limit, end < size ? end : size));
        return result;
    }


}
